package com.demo.cotroller;

import com.alibaba.fastjson.JSONObject;
import com.demo.bean.BaseUserDto;
import com.demo.bean.Student;
import com.demo.bean.UserDto;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wangzhanjin
 * @date 2018/6/11 15:24
 */
@Controller
@RequestMapping("/beanUtils")
public class BeanUtilsController {
    @RequestMapping()
    @ResponseBody
    public String beanUtils() {
        Map<String, String> map = new HashMap<>();
        map.put("user_code", "20180801");
        map.put("real_name", "猪猪");
        BaseUserDto dtoForMap = new BaseUserDto();
        BeanUtils.copyProperties(map,dtoForMap);

        UserDto userDto = new UserDto();
        userDto.setReal_name("map不行只能bean");
        BaseUserDto dtoForBean = new BaseUserDto();
        BeanUtils.copyProperties(userDto,dtoForBean);
        return "map："+dtoForMap.toString()+"；<br>bean："+dtoForBean.toString();
    }
}
